<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>插件注册</title>
    <#include "/common/plateform/include/common-base.ftl">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <#include "/common/plateform/top.ftl">
    <!-- top end -->
    <!-- left start -->
    <#include "/common/plateform/left-project.ftl">
    <!-- left end-->

    <div class="content-wrapper">
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!--搜索  start -->
                    <div class="box box-info">
                        <!--搜索title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-search"></i> 插件注册管理搜索</h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove">
                                    <i class="fa fa-times"></i></button>
                            </div>
                        </div>
                        <!--搜索title  end -->
                        <div class="box-body">
                            <form id="searchForm" class="form-horizontal" action="javascript:;">
                                <input name="pageName" type="hidden" value="sysPluginManager-list"/>
                                <input name="formName" type="hidden" value="searchForm"/>
                                <input name="sysPluginManager.w_delStatus" type="hidden" value="F"/>
                                <input name="orderBy" type="hidden" value="plugin_short_name"/>
                                <input type="hidden" name="sysPluginManager.w_sysName" class="sysEname" value=""/>
                                <div class="form-group">
                                    <div class="col-sm-2 text-right"><label class="control-label">插件简称：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control clean"
                                               name="sysPluginManager.wl_pluginShortName" value=""/>
                                    </div>
                                    <div class="col-sm-2 text-right"><label class="control-label">插件描述：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control clean"
                                               name="sysPluginManager.wl_pluginRemark" value=""/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-2 text-right"><label class="control-label">插件全称：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control clean"
                                               name="sysPluginManager.wl_pluginFullName" value=""/>
                                    </div>
                                    <div class="col-sm-2 text-right"><label class="control-label">插件类别：</label>
                                    </div>
                                    <div class="col-sm-4">
                                        <select id="searchForm_pluginType"
                                                name="sysPluginManager.w_pluginType"
                                                class="form-control  clean"
                                                data-temp-obj="sysName"
                                                data-dict-code="dictItemList"
                                                data-dict-cate="pluginType"
                                                data-colmun=""
                                                data-type-tag="select" data-def="">
                                            <option
                                                    value="">--请选择--
                                            </option>
                                        </select>
                                    </div>
                                </div>
                                <center>
                                    <div class="box-footer clearfix">
                                        <button type="button" class="btn btn-success"
                                                onclick="getTableData();"><i
                                                class="fa fa-search"></i> 查询
                                        </button>&nbsp;
                                        <button type="button" class="btn btn-warning"
                                                onclick="mytools.cleanData('#searchForm');">重置
                                        </button>
                                        <button type="button" class="btn btn-danger" onclick="loadCache();">数据同步 </button>
                                    </div>
                                </center>
                            </form>
                        </div>
                    </div>
                    <!-- 搜索 end -->


                    <div class="box box-success">
                        <!--列表title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title">插件注册管理列表 [<span id="span-sysname-text"></span>] [共计<span
                                    id="dataListTotalCount">0</span>条数据]
                                　　　
                                <button onclick="toAdd();" class="btn btn-success" type="button"><i
                                        class="fa fa-plus-circle"></i> 增加
                                </button>
                            </h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                            </div>
                        </div>
                        <!--列表title  end -->
                        <div class="box-body">
                            <table id="dataList" class="table table-bordered table-hover">
                                <thead class="bg-success">
                                <tr>
                                    <th width="40%">插件简称/插件全称</th>
                                    <th width="40%">类别/描述</th>
                                    <th width="20%">操作</th>
                                </tr>
                                </thead>
                                <tbody id="dataList-body">
                                </tbody>
                            </table>
                            <center>
                                <ul id="dataList-page"></ul>
                            </center>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- Main end -->

        <div class="modal fade" id="my_modal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="width:900px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">
                            <font color="red">信息添加/修改</font>&nbsp;
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="submitForm" action="javascript:;">
                            <input type="hidden" name="pageName" value="sysPluginManager-list"/>
                            <input type="hidden" name="formName" value="addForm"/>
                            <input type="hidden" id="w_infoId" class="clean" data-name="sysPluginManager.infoId" name="sysPluginManager.w_infoId"/>
                            <input type="hidden" id="formToken" name="formToken" value="${formToken}"/>
                            <input name="sysPluginManager.delStatus" type="hidden" value="F"/>

                            <div class="box-body" id="submitFormData">
                                <!-- Custom Tabs -->
                                <div class="nav-tabs-custom">
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="tab_1">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">插件所属系统</label>
                                                <div class="col-sm-10">
                                                    <input type="text" readonly="readonly" name="sysPluginManager.sysName" class="form-control sysEname" value=""/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">插件路径全称</label>
                                                <div class="col-sm-10">
                                                    <input type="text" id="pluginFullName"
                                                           name="sysPluginManager.pluginFullName"
                                                           data-name="sysPluginManager.pluginFullName"
                                                           class="form-control clean"
                                                           data-bv-notempty="true"
                                                           data-bv-notempty-message="此项不能为空"
                                                           data-bv-regexp="true"
                                                           data-bv-regexp-regexp="^[0-9a-zA-Z.]{1,}$"
                                                           data-bv-regexp-message="必须是字母、数字、点号"
                                                           placeholder="必填项，请输入插件类全名包路径地址">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">插件英文简称</label>
                                                <div class="col-sm-10">
                                                    <input type="text" id="pluginShortName"
                                                           name="sysPluginManager.pluginShortName"
                                                           data-name="sysPluginManager.pluginShortName"
                                                           class="form-control clean"
                                                           data-bv-notempty="true"
                                                           data-bv-notempty-message="此项不能为空"
                                                           placeholder="必填项，英文简称"
                                                           data-bv-regexp="true"
                                                           data-bv-regexp-regexp="^[0-9a-zA-Z]+$"
                                                           data-bv-regexp-message="必须是字母、数字">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">插件所属类型</label>
                                                <div class="col-sm-10">
                                                    <select id="submitForm_pluginType"
                                                            data-bv-notempty="true"
                                                            data-bv-notempty-message="此项不能为空"
                                                            name="sysPluginManager.pluginType"
                                                            class="form-control  clean"
                                                            data-temp-obj="sysName"
                                                            data-name="sysPluginManager.pluginType"
                                                            data-dict-code="dictItemList"
                                                            data-dict-cate="pluginType"
                                                            data-colmun=""
                                                            data-type-tag="select" data-def="">
                                                        <option
                                                                value="">--请选择--
                                                        </option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">插件中文描述</label>
                                                <div class="col-sm-10">
                                                    <textarea id="pluginRemark"
                                                              class="form-control clean"
                                                              name="sysPluginManager.pluginRemark"
                                                              data-name="sysPluginManager.pluginRemark"
                                                              rows="3" cols="50"
                                                              data-bv-notempty="true"
                                                              data-bv-notempty-message="此项不能为空"
                                                              placeholder="必填项，中文描述"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- /.tab-pane -->
                                    </div>
                                    <!-- /.tab-content -->
                                </div>
                                <!-- nav-tabs-custom -->
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-success pull-left"
                                        onclick="cannel();">取消
                                </button>
                                <button type="button" class="btn btn-danger pull-right"
                                        onclick="save('submitForm');">提 交
                                </button>
<#--                                <button type="button" class="btn btn-danger" onclick="loadCache();">数据同步 </button>-->
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>


        <script type="text/template" id="dataList-template">
            <? for ( var i = 0; i < rows.length; i++) {?>
            <tr>
                <td style="display:none;"><?=rows[i].infoId?></td>
                <td class="w300">
                    <?=(pageObj.currentPage-1)*10+(i+1)?>.<?=rows[i].sysPluginManager.pluginShortName?><br/>
                    <span title="<?=rows[i].sysPluginManager.pluginFullName?>"><?=rows[i].sysPluginManager.pluginFullName?>
                </td>
                <td class="w200">
                    <span class="fx2">[<?=dictListMap["pluginType"][rows[i].sysPluginManager.pluginType]?>]</span>/<br/>
                    <?=strUtil.doNull(rows[i].sysPluginManager.pluginRemark)?></td>
                <td>
                    <button type="button" class="btn btn-warning btn-xs"
                            onclick="toLoad('<?=rows[i].sysPluginManager.infoId?>','edit');">修改
                    </button>
                    <button type="button" class="btn btn-danger btn-xs"
                            onclick="toDele('<?=rows[i].sysPluginManager.infoId?>');">删除
                    </button>
                    <button type="button" class="btn btn-primary btn-xs"
                            onclick="toCache('pluginsCache','<?=rows[i].sysPluginManager.pluginShortName?>');">查看缓存
                    </button>
                </td>
            </tr>
            <?}?>
        </script>

        <script>
            var clickMenu = "sysPluginManager-list";
            var id, myPage, dataListId, searchFormId, isShowLog, tableId;
            myPage = 10;
            dataListId = "dataList";
            searchFormId = "searchForm";
            tableId = "infoId";
            isShowLog = true;
            var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
            $(".sysEname").val(defSysEname);
            $("#span-sysname-text").text(defSysEname+"-"+strUtil.getLocalStorage("sysCname"));
//            $("#searchForm_sysName").attr("data-condition","uctSys.w_sysEname="+defSysEname);
//            $("#submitFormData_sysName").attr("data-condition","uctSys.w_sysEname="+defSysEname);
//            $("#submitForm").find("input[name='sysPluginManager.sysName']").val(defSysEname);
            /**
             * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
             */
            var dictListMap = DictUtil.initDictAndDymic();
            $(function () {
                // $("#searchForm_sysName").val(defSysEname);
                //1、加载分页列表数据
                getTableData();
                //2、控制是否启用token
                //setToken();

                //请在下面补充其他初始化方法（如数据字典、页面加载数据等）

            });

            //读取（查询、编辑）数据
            function toLoad(id, type) {
                var paramLoadData = {
                    "sysPluginManager.w_infoId": id,
                    "pageName": "sysPluginManager-list","formName": "searchForm"
                };
                loadObj(type, paramLoadData);
            }

            function toDele(id) {
                var index_submit = layer.confirm('您确定要删除信息吗？', {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        var paramLoadData = {
                            "pageName": "sysPluginManager-list","formName": "delForm",
                            "sysPluginManager.w_infoId": id
                        };
                        doDele(paramLoadData);
                    });
            }

            //反显数据
            function showData(type, myData) {
                // console.log(myData);

                if ("view" == type) {
                    $("#my_modal_view").modal("show");

                } else if ("edit" == type) {
                    mytools.cleanData("#submitForm");
                    //FormUtil.fillData("#submitForm", myData,"id");
                    $("#submitForm").find("input[name='formName']").val("editForm");
                    $("#w_" + tableId).val(myData.infoId);
                    $("#my_modal").modal("show");
                }
                FormUtil.loadView("sysPluginManager", myData.sysPluginManager);
            }

            function subStrPlugin(str) {
                var ssp = str.split(".");
                return ssp[0] + "....." + ssp[4] + "." + ssp[5];
            }

            //加载列表数据
            function getTableData() {
                $.ajax({
                    type: 'get',
                    url: common_list_url,
                    data: $("#" + searchFormId).serialize() + getCurrentPage(common_list_url + "?" + $("#" + searchFormId).serialize(), myPage),
                    dataType: 'json',
                    success: function (myData) {
                        if (isShowLog) console.log(myData);
                        var data = baidu.template(dataListId + "-template", eval(myData));
                        $("#dataListTotalCount").text(myData.total);
                        $("#" + dataListId + "-body").html(data);
                        var option = {
                            ele: $("#" + dataListId + "-page")[0],
                            total: myData.total,
                            fn: getTableData,
                            url: common_list_url + "?" + $("#" + searchFormId).serialize()
                        }
                        generatePages(option);
                    }
                });
            }

            //打开添加页面
            function toAdd() {
                mytools.cleanData("#submitForm");
                $("#w_" + tableId).val("");
                $(".datepicker").val("");
                $("#submitForm").find("input[name='formName']").val("addForm");
                $("#submitForm_sysName").val(defSysEname);
                $('#my_modal').modal('show');
            }

            //获取对象值
            function loadObj(type, paramData) {
                $.ajax({
                    type: 'get',
                    url: common_info_url + "?doCode=dymicSql",
                    data: paramData,
                    async: false,
                    dataType: "json",
                    success: function (myData) {
                        showData(type, myData);
                    }
                });
            }

            //删除信息（逻辑删除）
            function doDele(paramData) {
                $.ajax({
                    type: "post",
                    url: common_submit_url + "?doCode=dymicSql",
                    data: paramData,
                    dataType: "json",
                    success: function (myData) {
                        var result = myData.flag;
                        if (result == "T") {
                            layer.alert("删除操作成功");
                            refresh();
                        }
                    }
                });
            }

            function loadCache(){
                var index_load = layer.msg("数据同步进行中。。。",{time:false});
                $.ajax({
                    type:'post',
                    url: common_cache_url+"init",
                    data:{"pageName":"sysPluginManager-list","formName":"initiCacheForm","sysPluginManager.w_sysName":defSysEname},
                    dataType:'json',
                    success: function(myData){
                        console.log("sysPluginManager.initiCacheForm",myData);
                        layer.close(index_load);
                        layer.alert(myData.msg);
                    }
                });
            }

            /**
             * 表单数据提交
             * @param formId
             */
            function save(formId) {
                var validate = $('#' + formId).data('bootstrapValidator').validate();
                if (!validate.isValid()) { //如果校验不通过就返回
                    return;
                }
                var index_submit = layer.confirm('您确定要提交信息吗？', {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        $.ajax({
                            type: "post",
                            url: common_submit_url,
                            data: $("#" + formId).serialize(),
                            dataType: "json",
                            success: function (myData) {
                                //console.log(myData);
                                if (myData.flag == "T") {
                                    layer.alert("数据保存成功");
                                    $("#my_modal").modal("hide");
                                } else {
                                    layer.alert(myData.msg);
                                }
                                refresh();
                            }
                        });
                    });
            }

            //关闭win
            function cannel(type) {
                if (strUtil.isNull(type)) {
                    $('#my_modal').modal('hide');
                } else {
                    $('#my_modal_' + type).modal('hide');
                }
            }

            function refresh() {
                getTableData();
            }


            function setToken() {
                $.ajax({
                    type: 'get',
                    url: ctx + '/sendPage/token?token=true',
                    dataType: 'text',
                    success: function (myData) {
                        console.log(myData);
                        $('#formToken').val(myData);
                    }
                });
            }

            //给模态窗口内form表单内的所有支持必填项的元素注入校验
            $(".modal").on('shown.bs.modal', function () {
                $(this).find("form").each(function () {
                    var formId = $(this).attr("id");
                    if (!strUtil.isNull(formId)) {
                        formId = "#" + formId;
                        setValidate(formId);//定义add表单验证属性
                        mytools.cleanValidate(formId);//清空上次校验规则提示
                    }
                });
            });

            //1.定义校验规则-定义
            function setValidate(id) {
                $(id).each(function () {
                    $(this).bootstrapValidator({
                        feedbackIcons: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        }, /** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                        fields: {
                            /** 可自定义新增验证规则
                             "uctUser.userEname":{
								validators: {
								regexp: {
								regexp: /^[0-9]+$/,
								message: '只能是数字'
								}
								}
								}
                             **/
                        }
                    });
                });
            }

            function toCache(spaceName, shortName) {
                $.ajax({
                    type: 'get',
                    url: common_cache_url + 'view',
                    data:{"cacheSpaceName":spaceName,"cachekey":"group_"+shortName},
                    dataType: 'json',
                    success: function (myData) {
                        console.log(myData);
                        if (myData.flag == "T") {
                            layer.open({
                                title: '查看缓存信息',
                                type: 1,
                                skin: 'layui-layer-demo', //样式类名
                                closeBtn: 0, //不显示关闭按钮
                                anim: 2,
                                shadeClose: true, //开启遮罩关闭
                                area: ['500px', '300px'],
                                content: "<div style='word-break:break-all;word-wrap:break-word;width:100%;padding:5px;'>" + myData.msg +"</div>"
                            });
                        } else {
                            layer.alert(myData.msg);
                        }
                    }
                });
            }
        </script>


    </div>
    <!-- /.content-wrapper -->
    <!-- foot start -->
    <#include "/common/plateform/foot.ftl">
    <!-- foot start -->

</div>
</body>


</html>
